<?php

namespace common\components;

use yii\base\Component;

/**
 * 组件基类
 *  里面有一些和业务相关的封装
 * Class BaseComponent
 */
class BaseComponent extends Component
{
    public $errorCode;
    public $errorMessage;

    /**
     * @param $errorCode
     */
    public function setErrorCode($errorCode) 
    {
        $this->errorCode = $errorCode;
    }

    /**
     * @param $errorMessage
     */
    public function setErrorMessage($errorMessage) 
    {
        $this->errorMessage = $errorMessage;
    }

    /**
     * 设置错误信息
     * @param array $error
     *  $error 是个key值固定的数组,$error['code'], $error['message']
     */
    public function setError($error) 
    {
        $this->errorCode = isset($error['code']) ? $error['code'] : '';
        $this->errorMessage = isset($error['message']) ? $error['message'] : '';
    }


    /**
     * 获取错误信息
     * @return array
     */
    public function getError() 
    {
        $error = [];
        $error['code'] = $this->errorCode;
        $error['message'] = $this->errorMessage;

        return $error;
    }
}